package com.siyu.prewarn.warnuser.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.siyu.common.core.controller.BaseController;
import com.siyu.common.core.domain.AjaxResult;
import com.siyu.common.core.page.TableDataInfo;
import com.siyu.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.siyu.prewarn.warnuser.domain.WarnUser;
import com.siyu.prewarn.warnuser.service.IWarnUserService;

/**
 * 报警条件-用户中间Controller
 *
 * @author hrhy
 * @date 2024-06-15
 */
@RestController
@RequestMapping("/prewarn/warnuser")
public class WarnUserController extends BaseController {
    @Autowired
    private IWarnUserService warnUserService;

    /**
     * 查询报警条件-用户中间列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WarnUser warnUser) {
        startPage();
        List<WarnUser> list = warnUserService.selectWarnUserList(warnUser);
        return getDataTable(list);
    }

    /**
     * 导出报警条件-用户中间列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, WarnUser warnUser) {
        List<WarnUser> list = warnUserService.selectWarnUserList(warnUser);
        ExcelUtil<WarnUser> util = new ExcelUtil<WarnUser>(WarnUser.class);
        util.exportExcel(response, list, "报警条件-用户中间数据");
    }

    /**
     * 获取报警条件-用户中间详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(warnUserService.selectWarnUserById(id));
    }

    /**
     * 新增报警条件-用户中间
     */
    @PostMapping
    public AjaxResult add(@RequestBody WarnUser warnUser) {
        return toAjax(warnUserService.insertWarnUser(warnUser));
    }

    /**
     * 修改报警条件-用户中间
     */
    @PutMapping
    public AjaxResult edit(@RequestBody WarnUser warnUser) {
        return toAjax(warnUserService.updateWarnUser(warnUser));
    }

    /**
     * 删除报警条件-用户中间
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(warnUserService.deleteWarnUserByIds(ids));
    }
}
